package com.starbaba.comment.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.base.common.database.BaseDao;
import com.base.common.exception.AppException;
import com.base.common.util.StringUtils;
import com.starbaba.activity.model.LoanProductVO;
import com.starbaba.comment.service.ActivityCommentService;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.loanActivity.model.UserCommentModel;
import com.starbaba.model.dictionary.Constant;
import com.starbaba.model.utils.JSONUtils;
import com.starbaba.redis.JedisUtils;


/**
 * 活动评价
 * @version 1.0
 */
@Component
@SuppressWarnings("rawtypes") 
public class ActivityCommentServiceImpl implements ActivityCommentService{

	@SuppressWarnings("deprecation")
    private static BaseDao dao = new BaseDao(Constant.POOL_LIFE);
	
	@Override
	public List<UserCommentModel> getCommentList(int iDisplayStart, int iDisplayLength, PageResponse pageResponse, Map<String, Object> paramsMap){
		String activityId = (String) paramsMap.get("activityId");
		String activityName = (String) paramsMap.get("activityName");
		String commentType = (String) paramsMap.get("commentType");
		String score = (String) paramsMap.get("score");
		
		String listSql = "SELECT c.id ,c.activity_id ,p.name ,c.user_name ,c.score ,c.comment ,c.create_time ,c.effective "
				+ "FROM loan_user_comment c,loan_product_info p WHERE c.activity_id = p.id ";
		
		String selectSql = "";
		if (!StringUtils.isEmpty(activityId)) {
            selectSql += " and c.activity_id = " + activityId ;
        }
		if (!StringUtils.isEmpty(activityName)) {
            selectSql += " and p.name like '%" + activityName + "% ";
        }
		if (!"0".equals(commentType)) {
			selectSql += " and c.comment_type =" +commentType;
		}
		if (!"0".equals(score)) {
            selectSql += " and c.score = " + score;
        }

		listSql += selectSql;
		listSql += " order by c.create_time desc limit " + iDisplayStart + " , " + iDisplayLength;

		String countSql = "select count(1) FROM loan_user_comment c,loan_product_info p WHERE c.activity_id = p.id " + selectSql;
		List<UserCommentModel> list = null;
		try {
			int count = dao.getInt(countSql);
			list = dao.list(listSql, UserCommentModel.class, new Object[] {});
			pageResponse.setITotalRecords(count);
			pageResponse.setITotalDisplayRecords(count);
		} catch (AppException e) {
			e.printStackTrace();
		}
		
		return list;
	}
	
}














